package com.zyf.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

public class FFmpegUtils {

    public static String execFFmpegCommand(List<String> command) throws Exception {
        ProcessBuilder builder = new ProcessBuilder(command);
        builder.redirectErrorStream(true);
        StringBuilder stringBuilder = new StringBuilder();
        InputStream inputStream =null;
        BufferedReader reader =null;
        try {
            Process process = builder.start();
            inputStream = process.getInputStream();
            reader = new BufferedReader(new InputStreamReader(inputStream));
            String line="";
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
                stringBuilder.append("\n");
            }
        } catch (Exception e) {
            throw new RuntimeException("ffmpeg执行异常" + e.getMessage());
        }finally {
            if (reader != null) {
                reader.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return stringBuilder.toString();
    }

}
